<template>
<div class="vue-box sbot sbot-fluid">
  <!-- 参数栏 -->
  <div class="c-panel">
    <el-form :inline="true">
      <!-- 表单 -->
      <sa-item v-model="m.sid" type="enum" jtype="3" :jv="dims.SD" name="所属服务" br />
      <sa-item v-model="m.type" type="enum" jtype="3" :jv="dims.MSG_TYPE" name="消息类型" br />
      <sa-item name="消息用户" br>
        <template>
          <el-select v-model="m.users" placeholder="请选择用户" filterable multiple collapse-tags clearable>
            <el-option v-for="(user, index) in allUsers" :key="index" :label="user.name" :value="user.id">
            </el-option>
          </el-select>
        </template>
      </sa-item>
      <sa-item v-model="m.msgText" type="text" name="消息内容" br />
      <sa-item v-model="m.status" type="enum" jtype="3" :jv="dims.YES_OR_NO" name="状态" br />
      <sa-item v-model="m.note" type="text" name="描述" br />
    </el-form>
  </div>
</div>
</template>

<script>
export default {
  name: 'sms-update-user',
  props: {
    param: Object
  },
  data() {
    return {
      // 超级对象
      m: this.createModel(),
      dims: sa.$sys.getCurd(),
      // 用户
    }
  },
  created: function () {
    this.allUsers = this.param.allUsers
    this.getInfo(this.param.id)
  },
  methods: {
    createModel() {
      return {}
    },
    // 变更
    ok() {
      // 表单校验
      let m = this.m;
      sa.checkNull(m.sid, '请选择所属服务');
      sa.checkNull(m.type, '请选择消息类型');

      // 变更
      sa.ajax('/msg/user/update', sa.removeNull(m), function (res) {
        if (res.code == 200) {
          sa.alert(res.msg, function () {
            this.m = this.createModel();
            sa.closeModel();
            sa.currView().f5();
          }.bind(this));
        }
      }.bind(this), {
        type: 'post'
      });
    },
    //查询详情
    getInfo(id) {
      sa.ajax('/msg/user/getById', {
        id: id
      }, function (res) {
        this.m = res.data;
        this.m.users = res.data.users.map((id) => {
          return String(id);
        });
      }.bind(this), {
        type: 'get'
      });
    },
  }
}
</script>

<style scoped>
</style>
